package com.gemini.main.protobuf;

import com.googlecode.protobuf.format.JsonFormat;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * gemini
 * com.gemini.main.protobuf.McflyDataTest
 *
 * @author zhanghailin
 */
public class McflyDataTest {

    public static void main(String[] args) throws Exception {
        File file = new File("C:\\Users\\user\\Desktop\\变量植保的处方图示例");
        // get the folder list
        File[] array = file.listFiles();
        for (int i = 0; i < array.length; i++) {
            if (array[i].isFile()) {
                protobuf2Json(array[i].getPath());
            } else if (array[i].isDirectory()) {
            }
        }
        /*protobuf2Json("C:\\Users\\user\\Desktop\\变量植保的处方图示例\\15350963458812982835431128394280_20181031134352_Spray.dat");
        protobuf2Json("C:\\Users\\user\\Desktop\\变量植保的处方图示例\\15350963458812982835431128394280_20181031134352_Spray.dat");
        protobuf2Json("C:\\Users\\user\\Desktop\\变量植保的处方图示例\\15350963458812982835431128394280_20181031134352_Spray.dat");
        protobuf2Json("C:\\Users\\user\\Desktop\\变量植保的处方图示例\\15350963458812982835431128394280_20181031134352_Spray.dat");
        protobuf2Json("C:\\Users\\user\\Desktop\\变量植保的处方图示例\\15350963458812982835431128394280_20181031134352_Spray.dat");
        protobuf2Json("C:\\Users\\user\\Desktop\\变量植保的处方图示例\\15350963458812982835431128394280_20181031134352_Spray.dat");
        protobuf2Json("C:\\Users\\user\\Desktop\\变量植保的处方图示例\\15350963458812982835431128394280_20181031134352_Spray.dat");
        protobuf2Json("C:\\Users\\user\\Desktop\\变量植保的处方图示例\\15350963458812982835431128394280_20181031134352_Spray.dat");
        protobuf2Json("C:\\Users\\user\\Desktop\\变量植保的处方图示例\\15350963458812982835431128394280_20181031134352_Spray.dat");
        protobuf2Json("C:\\Users\\user\\Desktop\\变量植保的处方图示例\\15350963458812982835431128394280_20181031134352_Spray.dat");
        protobuf2Json("C:\\Users\\user\\Desktop\\变量植保的处方图示例\\15350963458812982835431128394280_20181031134352_Spray.dat");*/







    }

    private static void protobuf2Json(String filepath) throws IOException {
        InputStream in1 = new FileInputStream(filepath);
        DataProtobuf.Data mcflyData1 = DataProtobuf.Data.parseFrom(in1);
        System.out.println(JsonFormat.printToString(mcflyData1));
        in1.close();
    }

    private static void protobuf2Json2(String filepath) throws IOException {
        System.out.println(filepath);
        InputStream in1 = new FileInputStream(filepath);
        DataOldProtobuf.Data mcflyData1 = DataOldProtobuf.Data.parseFrom(in1);
        System.out.println(JsonFormat.printToString(mcflyData1));
        in1.close();
    }
}
